package com.js.domian.model.bot.support;

import cn.hutool.core.annotation.Alias;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.js.domian.model.bot.analysis.MessageChain;
import com.js.domian.model.bot.BaseApi;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;

public class SendPrivateMsg extends BaseApi {

    private final Param param;

    public SendPrivateMsg(long userId, MessageChain messageChain) {
        this.param = new Param();
        this.param.setUserId(userId);
        this.param.setMessage(JSONUtil.parseArray(messageChain.toMessageString()));
        this.param.setAutoEscape(false);
    }

    public SendPrivateMsg(long userId, MessageChain messageChain, boolean autoEscape) {
        this.param = new Param();
        this.param.setUserId(userId);
        this.param.setMessage(JSONUtil.parseArray(messageChain.toMessageString()));
        this.param.setAutoEscape(autoEscape);
    }

    @Override
    public String getAction() {
        return "send_private_msg";
    }

    @Override
    public Object getParams() {
        return param;
    }

    @Data
    @NoArgsConstructor(access = AccessLevel.PRIVATE)
    public static class Param {

        @Alias("user_id")
        private long userId;

        @Alias("message")
        private JSONArray message;

        @Alias("auto_escape")
        private boolean autoEscape;

    }
}
